import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types'

class TodoItem extends Component {

    constructor(props) {
        super(props);
        this.handleClick = this.handleClick.bind(this)
    }

    render () {
        const { content } = this.props;
        return (
            <Fragment>
                <div onClick={this.handleClick}>{content}</div>
            </Fragment>
        );
    }

    handleClick() {
        const { deleteItem, index } = this.props;
        deleteItem(index)
    }
}

// 类型校验
TodoItem.propTypes = {
    content: PropTypes.string.isRequired,
    deleteItem: PropTypes.func,
    index: PropTypes.number
}

// 默认值
TodoItem.defaultProps = {
    content: 'test'
}

export default TodoItem;